from django.shortcuts import render_to_response
from django.http import HttpResponse
from blog.models import Employee


class Person():
    def __init__(self,name,age,title):
        self.name = name
        self.age = age
        self.title = title
    def read(self):
        return  '%s is reading'%self.name

def index(request):
    # return HttpResponse('<h1>hello django!<h1/>')
    user = {'name':'tom','age':'22','title':'my data'}
    # books = ['python','java','php','web'] 列表
    # user = Person('tony',21,'FUCK') 可以传实例
    emps = Employee.objects.all()
    return render_to_response('index.html', {'books':emps,'user':user})

  #  1. emp = Employee()
  #     emp.name = 'Alen'
  #     emp.save()
  #     通过对属性的赋值 来写入数据
  #
  #  2. emp = Employee(name='Tom')
  #     emp.save()  通过直接传参的方式 写入数据
  #  3. Employee.objects.create(name='Alex') 返回一个对象
  #     通过直接调用数据库的引擎来写入数据




